package com.relax.netty.zerocopy;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NewClient {
    public static void main(String[] args) throws IOException {
        final SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 8899));
        socketChannel.configureBlocking(true);

        final FileChannel fileChannel = new FileInputStream("/Users/zoeychen/Downloads/DingTalk_v4.7.15.7.dmg").getChannel();
        long timeStart = System.currentTimeMillis();
        //transferTo底层使用零拷贝
        final long transferCount = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println("传送字节:" + transferCount + ",耗时:" + (System.currentTimeMillis() - timeStart));
        socketChannel.close();
    }
}
